home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / 3D_Rendering / Musgrave_Shaders / Source / puffyclouds.sl < prev    next >
Encoding:
Text File  |  1994-12-08  |  2.5 KB  |  79 lines

  1. /*
  2.  * puffyclouds.sl -- RenderMan compatible surface shader for puffy
  3.  *                   clouds.
  4.  *
  5.  * DESCRIPTION:
  6.  *    Makes nice looking cumulous clouds like you would see in the sky
  7.  *    on a bright sunny day.  Works as a basic thresholded fBm.  Since
  8.  *    this texture is generally used as a backdrop, it does not take
  9.  *    lighting into account.  If you wanted a lit surface that looked like
  10.  *    puffy clouds (like painted clouds on a wall), then it would be pretty
  11.  *    easy to add the lighting.
  12.  *
  13.  * PARAMETERS:
  14.  *    txtscale - overall scaling factor
  15.  *    skycolor, cloudcolor - the obvious meanings
  16.  *    octaves, omega, lambda - control the fractal appearance of the clouds
  17.  *    threshold - fBm sum below this level is just blue sky
  18.  *
  19.  * ANTIALIASING:
  20.  *    None, but should be easy to add antialiasing simply by adaptively
  21.  *    setting the "octaves" parameter based on distance from eye point.
  22.  *
  23.  * AUTHOR:
  24.  *    C language version by F. Kenton Musgrave
  25.  *    Translation to RenderMan Shading Language by Larry Gritz.
  26.  *
  27.  * REFERENCES:
  28.  *    _Texturing and Modeling: A Procedural Approach_, by David S. Ebert, ed.,
  29.  *    F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, and Steven Worley.
  30.  *    Academic Press, 1994.  ISBN 0-12-228760-6.
  31.  *
  32.  * HISTORY:
  33.  *    ??? - original C language version by Ken Musgrave
  34.  *    Apr 94 - translation to Shading Language by L. Gritz
  35.  *
  36.  * this file last updated 18 Apr 1994
  37.  */
  38.  
  39.  
  40.  
  41. /* Use signed Perlin noise */
  42. #define snoise(x) ((2*noise(x))-1)
  43.  
  44.  
  45. surface
  46. puffyclouds (float Ka = 0, Kd = 0;
  47.          float txtscale = 1;
  48.          color skycolor = color(.15, .15, .6);
  49.          color cloudcolor = color(1,1,1);
  50.          float octaves = 8, omega = 0.5, lambda = 2;
  51.          float threshold = 0;
  52.          )
  53. {
  54.   float value;
  55.   color Ct;      /* Color of the surface */
  56.   point PP;      /* Surface point in shader space */
  57.   float i, a, l, o;
  58.  
  59.   PP = txtscale * transform ("shader", P);
  60.  
  61.   /* Use fractional Brownian motion to compute a value for this point */
  62. /*  value = fBm (PP, omega, lambda, octaves); */
  63.   value = 0;
  64.   l = 1;  o = 1;  a = 0;
  65.   for (i = 0;  i < octaves;  i += 1) {
  66.       a += o * snoise (PP*l);
  67.       l *= 2;  o *= omega;
  68.     }
  69.   value = a;
  70.  
  71.   Ct = mix (skycolor, cloudcolor, smoothstep (threshold, 1, value));
  72.   
  73.   /* Shade like matte, but use color Ct */
  74.   Oi = 1;    /* Make it opaque */
  75.   Ci = Ct;   /* This makes the color disregard the lighting */
  76.   /* Uncomment the next line if you want the surface to actually be lit */
  77. /*  Ci = Ct * (Ka * ambient() + Kd * diffuse(faceforward(N,I))); */
  78. }
  79.